package com.lazy.configuration;

import com.lazy.aspect.IdempotentAspect;
import com.lazy.expression.ExpressionKeyResolver;
import com.lazy.template.CacheTemplate;
import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;


/**
 * @author fengshaoyu
 * @date 2024/1/30 16:55
 */
@Configuration
public class CustomRedisConfiguration {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Bean
    @ConditionalOnMissingBean(ExpressionKeyResolver.class)
    public ExpressionKeyResolver expressionKeyResolver(){
        return new ExpressionKeyResolver();
    }

    @Bean
    @ConditionalOnMissingBean(IdempotentAspect.class)
    public IdempotentAspect idempotentAspect() {
        return new IdempotentAspect(stringRedisTemplate,expressionKeyResolver());
    }

    @Bean
    @ConditionalOnMissingBean(CacheTemplate.class)
    public CacheTemplate cacheTemplate() {
        return new CacheTemplate();
    }
}
